import argparse,sys,lrc,pygame,os,time
from eyed3 import mp3
parserz = argparse.ArgumentParser(description='music player')
parserz.add_argument("url")
def mp3_bit(mp3Path):
        mp3Info = mp3.Mp3AudioFile(mp3Path)
        # print(mp3Info.info.bit_rate[1])
        return (mp3Info.info.bit_rate[1],mp3Info.info.time_secs)
def maths(strs):
    i=strs.split(":")
    i1=int(i[0])
    i=i[1].split(".")
    i2=int(i[0])
    i3=int(i[1])
    return i3+i2*1000+i1*60000
args=parserz.parse_args()
try:
    link=args.url
except:
    sys.exit(0)
lrc_file=lrc.readLRC(link+".lrc")
title=lrc_file.pop("title","None")
people=lrc_file.pop("name","None")
print("准备播放:",title,"-",people)
os.system("title music_player : "+title+" - "+people)
pygame.init()
pygame.mixer.init()
pygame.mixer.music.set_volume(0.7)
pygame.mixer.music.load(link)
pygame.mixer.music.play()
long=mp3_bit(link)[1]
while True:
    pos=pygame.mixer.music.get_pos()
    if pos==-1:
        print("播放完成\n5秒后退出")
        time.sleep(5)
        sys.exit(0)
    sec=(pos//1000)%60
    ssec=pos%1000
    min=pos//60000
    for i,j in reversed(lrc_file.items()):
        tmp=maths(i)
        if tmp<pos:
            os.system("cls")
            print(str(min)+":"+str(sec)+"."+str(ssec)+"/"+str(int(long//60))+":"+str(int(long%60))+".000")
            print(j)
            break
    time.sleep(0.05)